{extend name="public:base" /}
{block name="breadcrumbs"}
<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>
						<ul class="breadcrumb">
							<li>
								<i class="icon-home home-icon"></i>
								<a href="{:url('Index/index')}">首页</a>
							</li>
							<li class="active">用户组管理</li>
						</ul><!-- .breadcrumb -->
					</div>
{/block}					
{block name="content"}
	<div class="page-header">
		<h1>
			当前操作
			<small>
				<i class="icon-double-angle-right"></i>
				配置权限
			</small>
		</h1>
	</div>
	<div class="row">
	<form class="form-horizontal" id="group_access">
		<div class="col-xs-12">
			<div class="form-group">
				<label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 用户组名：  </label>
				<div class="col-sm-10">
					<input name="title" id="title" value="{$group.title}" class="col-xs-10 col-sm-4" type="text">
					<input name="id" id="id" type="hidden" value="{$group.id}">
					<input name="rules" id="rules" type="hidden" value="{$group.rules}">
				</div>
			</div>
		</div>
	</form>
		<div class="col-xs-12">
			<div class="table-responsive">
											<table id="sample-table-1" class="table table-striped table-bordered table-hover">
												<thead>
													<tr>
														<th class="center" style="width:50px;">
															<label>
																<input type="checkbox" class="ace" id="checkall">
																<span class="lbl"></span>
															</label>
														</th>
														<th>资源名称</th>
														<th>控制器/方法</th>
														<th class="hidden-480">状态</th>
													</tr>
												</thead>
												<tbody>
													
												{volist name="list" id="data"}
													<tr class="">
														<td class="center">
															<label>
																<input type="checkbox" class="ace ids" name="ids"  pid="{$data.pid}" value="{$data.id}">
																<span class="lbl"></span>
															</label>
														</td>

														<td style="padding-left:{$data.leftspace}px">
															<span style="padding-left:20px;">
															{if condition="$data.pid eq '0'"}
																<strong>{$data.leftstr}{$data.title}{$data.id}</strong>
															{else /} 
															{$data.leftstr}{$data.title}
															{/if}
															
															
															</span>				
														</td>
														<td>{$data.name}</td>
														<td class="hidden-480">
															{eq name="data.status" value="1"}<span>开启</span>{/eq}
															{eq name="data.status" value="0"} <span style="color:red;">禁用</span>{/eq}
														</td>													
														
														
													</tr>
													{/volist}

												</tbody>
											</table>
										</div>
		</div>	
		<div class="col-xs-12">
			<div class="clearfix">
						<div class="col-md-offset-3 col-md-9">
							<button class="btn btn-info" id="send">
								<i class="icon-ok bigger-110"></i>
								保存
							</button>		
							
						</div>
			</div>	
		</div>
	</div>

{/block}
{block name="script"}
	<script type="text/javascript">
	/*
	*已授权选中
	*/
	$(function(){
		var rules=$("#rules").val();
		var arr=rules.split(',');
		$.each(arr,function(){
			var id=this;
			$("[name='ids']").each(function(index, element) {			
					if($(this).val()==id){
						$(this).prop('checked',true);
					}
				});
		});
	});
	/*
	*全选或取消
	*/
	$("#checkall").click(function(){
		if($(this).is(':checked')){
			$("[name='ids']").each(function(index, element) {
				$(this).prop('checked',true);
			});
		}else{
			$("[name='ids']").each(function(index, element) {
				$(this).prop('checked',false);
			});
		}		
	});
	/*
	*部分选择或取消
	*/
	$(".ids").click(function(){				
		var pid=$(this).attr('pid');
		var id=$(this).val();
		if($(this).is(':checked')){
			$("[name='ids']").each(function(index, element) {            
            if(pid!=0&&pid==$(this).val()){
            	$(this).prop('checked',true);
            }          
        });
			 if(pid==0){
	            	$("[name='ids']").each(function(index, element) {
	            		var pidsub=$(this).attr('pid');
	            		if(pidsub==id){
	            			$(this).prop('checked',true);
	            		}
	            	});
	            }			
			
		}else{
			 if(pid==0){
	            	$("[name='ids']").each(function(index, element) {
	            		var pidsub=$(this).attr('pid');
	            		if(pidsub==id){
	            			$(this).prop('checked',false);
	            		}
	            	});
	            }
		}
	});
	/*
	*提交
	*/
	$("#send").click(function(){
		var val="";
		$("[name='ids']").each(function(index, element) {
			if($(this).is(':checked')){
				val += $(this).val() + ",";
			}
            
        });
		if(val.length>0){
			val=val.substring(0, val.length - 1); 
		}
		if(val.length>0){
			$("#rules").val(val);
			$.post(
					"{:url('group/group_access')}",
					$("#group_access").serializeArray(),
					function(d){
						if(d.status){
							layer.msg(d.msg, {time: 3000, icon:6},function(){
								window.location.href="{:url('group/index')}";	
							});		
						}else{
							layer.msg(d.msg, {time: 3000, icon:6});	
							//window.location.href="{:url('group/index')}";
						}
					}
				);
		}
	});
	
	</script>
{/block}